package com.edu.networkexperimentation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.networkexperimentation.common.ErrorCode;
import com.edu.networkexperimentation.exception.BusinessException;
import com.edu.networkexperimentation.mapper.ProcessMapper;
import com.edu.networkexperimentation.model.domain.Relation;
import com.edu.networkexperimentation.model.response.ResponseAlgorithmTableData;
import com.edu.networkexperimentation.service.ProcessService;
import com.edu.networkexperimentation.service.RelationService;
import org.springframework.stereotype.Service;
import com.edu.networkexperimentation.model.domain.Process;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author 29764
* @description 针对表【process】的数据库操作Service实现
* @createDate 2024-05-17 16:43:09
*/
@Service
public class ProcessServiceImpl extends ServiceImpl<ProcessMapper, Process>
    implements ProcessService{

    @Resource
    private RelationService relationService;

    @Override
    public ResponseAlgorithmTableData getAlgorithmTableData(Long id) {
        QueryWrapper<Relation> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Relation::getPaperid, id);
        Relation relation = relationService.getOne(wrapper);
        if (relation == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "无该试卷");
        }
        wrapper.clear();
        wrapper.lambda().eq(Relation::getFlag, relation.getFlag());
        List<Relation> relations = relationService.list(wrapper);
        List<Process> processes = new ArrayList<>();
        processes.add(null);processes.add(null);processes.add(null);
        int i = 0;
        for (Relation relation1 : relations) {
            QueryWrapper<Process> wrapper1 = new QueryWrapper<>();
            wrapper1.lambda().eq(Process::getPaperid, relation1.getPaperid());
            Process process = this.getOne(wrapper1);
            processes.set(process.getType(), process);
        }

        return new ResponseAlgorithmTableData(processes.get(0), processes.get(1), processes.get(2));
    }
}




